home *** CD-ROM | disk | FTP | other *** search
- /* *******************************
-
- File: Preferences.c
- Function: Handle all operations for this Modal Dialog
- History: 9/21/89 Original by Prototyper.
- Modified: 10/3/89 by Kirk Chase. Clean up routines
-
- ******************************* */
-
- #include "Preferences.h"
-
- static pascal char MyFilter (DialogPtr theDialog, EventRecord *theEvent, short *itemHit);
-
- static void Refresh_Dialog(DialogPtr GetSelection);
-
-
- /* *********************************** */
- /* These are the other includes for general routines */
-
- #include "string.h"
- #include "pascal.h"
- #include "Messenger.h"
-
- /* *********************************** */
- #define NIL 0
-
- #define I_OK 1
- #define I_Cancel 2
- #define I_B1Text 8
- #define I_B2Text 9
- #define I_B3Text 10
- #define I_CQText 11
- #define I_Default 16
- #define I_Icons 17
- #define I_Buttons 18
- #define I_Position 19
- static char ExitDialog;
- static Point myPt;
- static char ChangedSelection;
- static MenuHandle tempMenu;
- static long Result;
- static short Popup_I_Default;
- static short Popup_I_Icons;
- static short Popup_I_Buttons;
- static short Popup_I_Position;
- static Rect PopUpDefaultRect, PopUpIconRect, PopUpButtonsRect, PopUpCenterRect;
-
- /* ********************************************* */
-
- /* RefreshDialog()
- Draw non-dialog items */
- static void Refresh_Dialog(GetSelection)
- DialogPtr GetSelection;
- {
- Rect tempRect;
- short DType;
- Handle DItem;
-
- /* Do Default Button */
- GetDItem(GetSelection,I_OK, &DType, &DItem, &tempRect);
- PenSize(3, 3);
- InsetRect(&tempRect, -4, -4);
- FrameRoundRect(&tempRect, 16, 16);
- PenSize(1, 1);
-
- /* Draw the dividing lines */
- MoveTo(30,60);
- LineTo(371,60);
- MoveTo(28,24);
- LineTo(370,24);
- MoveTo(33,148);
- LineTo(370,148);
- MoveTo(245,155);
- LineTo(245,234);
-
- /* Draw PopUps */
- TextFont(systemFont);
- TextSize(12);
-
- /* Draw Default PopUp */
- MoveTo(220,49);
- DrawString("\pDefault:");
- SetRect(&tempRect,274,36,301,53);
- EraseRect(&tempRect);
- MoveTo(287,49);
- switch (Popup_I_Default) {
- case 1:
- DrawString("\p1");
- break;
- case 2:
- DrawString("\p2");
- break;
- case 3:
- DrawString("\p3");
- break;
- default:
- DrawString("\p????");
- break;
- }
-
- FrameRect(&tempRect);
- MoveTo(tempRect.left + 1, tempRect.bottom);
- LineTo(tempRect.right, tempRect.bottom);
- LineTo(tempRect.right, tempRect.top + 1);
-
- /* Draw PopUp Icons */
- MoveTo(30,209);
- DrawString("\pIcons:");
- SetRect(&tempRect,72,196,141,213);
- EraseRect(&tempRect);
- MoveTo(85,209);
- switch (Popup_I_Icons) {
- case 1:
- DrawString("\pNone");
- break;
- case 2:
- DrawString("\pStop");
- break;
- case 3:
- DrawString("\pNote");
- break;
- case 4:
- DrawString("\pCaution");
- break;
- default:
- DrawString("\p????");
- break;
- }
- FrameRect(&tempRect);
- MoveTo(tempRect.left + 1, tempRect.bottom);
- LineTo(tempRect.right, tempRect.bottom);
- LineTo(tempRect.right, tempRect.top + 1);
-
- /* Draw PopUp Buttons */
- MoveTo(85,49);
- DrawString("\pButtons:");
- SetRect(&tempRect,142,36,169,53);
- EraseRect(&tempRect);
- MoveTo(155,49);
- switch (Popup_I_Buttons) {
- case 1:
- DrawString("\p0");
- break;
- case 2:
- DrawString("\p1");
- break;
- case 3:
- DrawString("\p2");
- break;
- case 4:
- DrawString("\p3");
- break;
- default:
- DrawString("\p????");
- break;
- }
- FrameRect(&tempRect);
- MoveTo(tempRect.left + 1, tempRect.bottom);
- LineTo(tempRect.right, tempRect.bottom);
- LineTo(tempRect.right, tempRect.top + 1);
-
- /* Draw Position PopUp */
- MoveTo(30,174);
- DrawString("\pPosition:");
- SetRect(&tempRect,89,161,168,178);
- EraseRect(&tempRect);
- MoveTo(102,174);
- switch (Popup_I_Position)
- {
- case 1:
- DrawString("\pCentered");
- break;
- case 2:
- DrawString("\pTop Third");
- break;
- default:
- DrawString("\p????");
- break;
- }
- FrameRect(&tempRect);
- MoveTo(tempRect.left + 1, tempRect.bottom);
- LineTo(tempRect.right, tempRect.bottom);
- LineTo(tempRect.right, tempRect.top + 1);
- } /* end of Refresh_Dialog */
-
- /* ********************************************* */
-
- /* MyFilter()
- Filter proc for modal dialog; just checks for updates and PopUp menus */
- static pascal char MyFilter (theDialog, theEvent, itemHit)
- DialogPtr theDialog;
- EventRecord *theEvent;
- short *itemHit;
- {
- char theExit;
-
- theExit = FALSE;
- if (theEvent->what == updateEvt) Refresh_Dialog(theDialog);
- if (theEvent->what == mouseDown) { /* Mouse Down, check if in PopUps */
- myPt = theEvent->where;
- GlobalToLocal(&myPt);
-
- if (PtInRect(myPt,&PopUpDefaultRect) || PtInRect(myPt,&PopUpIconRect)
- || PtInRect(myPt,&PopUpButtonsRect) || PtInRect(myPt,&PopUpCenterRect)) {
- *itemHit = 999; /* PopUp Menu Flag */
- theExit = TRUE;
- } /* in a PopUp */
- }
-
- return(theExit);
- } /* End of MyFilter */
-
- /* ********************************************* */
-
- /* D_Preferences()
- Preference dialog to handle text dialog options */
- void D_Preferences()
- {
- DialogPtr GetSelection;
- Rect tempRect;
- short DType;
- Handle DItem;
- short itemHit;
-
- GetSelection = GetNewDialog(2, NIL, (WindowPtr)-1);
-
- SetRect(&PopUpCenterRect, 25,160,175,180);
- SetRect(&PopUpButtonsRect, 80,35,176,55);
- SetRect(&PopUpDefaultRect, 215,35,308,55);
- SetRect(&PopUpIconRect, 25,195,148,215);
-
- /* Setup initial conditions */
- Popup_I_Default = MInfo.defaultItem;
- Popup_I_Icons = MInfo.dIcon + 2;
- Popup_I_Buttons = MInfo.Buttons + 1;
- Popup_I_Position = MInfo.dPlace - 1;
- GetDItem(GetSelection,I_B1Text, &DType, &DItem, &tempRect);
- SetIText(DItem, MInfo.Button1);
- GetDItem(GetSelection,I_B2Text, &DType, &DItem, &tempRect);
- SetIText(DItem, MInfo.Button2);
- GetDItem(GetSelection,I_B3Text, &DType, &DItem, &tempRect);
- SetIText(DItem, MInfo.Button3);
- GetDItem(GetSelection,I_CQText, &DType, &DItem, &tempRect);
- SetIText(DItem, MInfo.CharEquiv);
-
- ShowWindow(GetSelection);
- SelectWindow(GetSelection);
- SetPort(GetSelection);
-
- ExitDialog = FALSE;
- FlushEvents(everyEvent, 0);
- do { /* Modal Dialog Loop */
- ModalDialog(&MyFilter, &itemHit);
- GetDItem(GetSelection, itemHit, &DType, &DItem, &tempRect);
-
- if ((itemHit == I_OK) || (itemHit == I_Cancel)) ExitDialog =TRUE;
-
- if (itemHit == 999) { /* Check for PopUp Menu */
- ChangedSelection = FALSE;
-
- if (PtInRect(myPt,&PopUpDefaultRect)) { /* check in PopUpDefault */
- tempMenu= GetMenu(51);
- if (tempMenu != NIL) { /* Got Menu */
- InsertMenu (tempMenu,-1);
- SetRect(&tempRect,215,37,275,53);
- InvertRect(&tempRect);
- myPt.v = 37;
- myPt.h = 275;
- LocalToGlobal(&myPt);
-
- CheckItem(tempMenu,Popup_I_Default,TRUE);
- Result = PopUpMenuSelect(tempMenu, myPt.v, myPt.h, Popup_I_Default);
-
- if ((Popup_I_Default != LoWord(Result)) && (LoWord(Result) > 0)) {
- CheckItem(tempMenu,Popup_I_Default,FALSE);
- ChangedSelection = TRUE;
- Popup_I_Default = LoWord(Result);
- } /* Changed Selection */
-
- DeleteMenu(51);
- InvertRect(&tempRect);
-
- if (ChangedSelection == TRUE) { /* Redraw Menu */
- SetRect(&tempRect,275,37,300,52);
- EraseRect(&tempRect);
-
- MoveTo(tempRect.left + 12,tempRect.top + 12);
- switch (Popup_I_Default) {
- case 1:
- DrawString("\p1");
- break;
- case 2:
- DrawString("\p2");
- break;
- case 3:
- DrawString("\p3");
- break;
- default:
- break;
- } /* of switch */
- } /* end of Redraw Menu */
- } /* end of Got Menu */
- } /* end of check PopUpDefault */
-
- if (PtInRect(myPt,&PopUpIconRect)) { /* Check PopUpIcon */
- tempMenu= GetMenu(52);
- if (tempMenu != NIL) { /* Got Menu */
- InsertMenu (tempMenu,-1);
- SetRect(&tempRect,25,197,73,213);
- InvertRect(&tempRect);
- myPt.v = 197;
- myPt.h = 73;
- LocalToGlobal(&myPt);
-
- CheckItem(tempMenu,Popup_I_Icons,TRUE);
- Result = PopUpMenuSelect(tempMenu, myPt.v, myPt.h, Popup_I_Icons);
-
- if ((Popup_I_Icons != LoWord(Result)) && (LoWord(Result) > 0)) {
- CheckItem(tempMenu,Popup_I_Icons,FALSE);
- ChangedSelection = TRUE;
- Popup_I_Icons = LoWord(Result);
- } /* Changed Selection */
-
- DeleteMenu(52);
- InvertRect(&tempRect);
-
- if (ChangedSelection == TRUE) { /* Redraw Menu */
- SetRect(&tempRect,73,197,140,212);
- EraseRect(&tempRect);
-
- MoveTo(tempRect.left + 12,tempRect.top + 12);
- switch (Popup_I_Icons) {
- case 1:
- DrawString("\pNone");
- break;
- case 2:
- DrawString("\pStop");
- break;
- case 3:
- DrawString("\pNote");
- break;
- case 4:
- DrawString("\pCaution");
- break;
- default:
- break;
- }
- } /* end of Redraw Menu */
- } /* end of Got Menu */
- } /* end of Check PopUpIcon */
-
- if (PtInRect(myPt,&PopUpButtonsRect)) { /* Check PopUpButtons */
- tempMenu= GetMenu(53);
- if (tempMenu != NIL) { /* Got Menu */
- InsertMenu (tempMenu,-1);
- SetRect(&tempRect,80,37,143,53);
- InvertRect(&tempRect);
- myPt.v = 37;
- myPt.h = 143;
- LocalToGlobal(&myPt);
-
- CheckItem(tempMenu,Popup_I_Buttons,TRUE);
- Result = PopUpMenuSelect(tempMenu, myPt.v, myPt.h, Popup_I_Buttons);
-
- if ((Popup_I_Buttons != LoWord(Result)) && (LoWord(Result) > 0)) {
- CheckItem(tempMenu,Popup_I_Buttons,FALSE);
- ChangedSelection = TRUE;
- Popup_I_Buttons = LoWord(Result);
- } /* Changed Selection */
-
- DeleteMenu(53);
- InvertRect(&tempRect);
-
- if (ChangedSelection == TRUE) { /* Redraw Menu */
- SetRect(&tempRect,143,37,168,52);
- EraseRect(&tempRect);
-
- MoveTo(tempRect.left + 12,tempRect.top + 12);
- switch (Popup_I_Buttons) {
- case 1:
- DrawString("\p0");
- break;
- case 2:
- DrawString("\p1");
- break;
- case 3:
- DrawString("\p2");
- break;
- case 4:
- DrawString("\p3");
- break;
- default:
- break;
- }
- } /* end of RedrawMenu */
- } /* end of Got Menu */
- } /* end of Check PopUpButtons */
-
- if (PtInRect(myPt,&PopUpCenterRect)) { /* Check PopUpCenter */
- tempMenu= GetMenu(54);
- if (tempMenu != NIL) { /* Got Menu */
- InsertMenu (tempMenu,-1);
- SetRect(&tempRect,25,162,90,178);
- InvertRect(&tempRect);
- myPt.v = 162;
- myPt.h = 90;
- LocalToGlobal(&myPt);
-
- CheckItem(tempMenu,Popup_I_Position,TRUE);
- Result = PopUpMenuSelect(tempMenu, myPt.v, myPt.h, Popup_I_Position);
-
- if ((Popup_I_Position != LoWord(Result)) && (LoWord(Result) > 0)) {
- CheckItem(tempMenu,Popup_I_Position,FALSE);
- ChangedSelection = TRUE;
- Popup_I_Position = LoWord(Result);
- } /* Changed Selection */
-
- DeleteMenu(54);
- InvertRect(&tempRect);
-
- if (ChangedSelection == TRUE) { /* Redraw Menu */
- SetRect(&tempRect,90,162,167,177);
- EraseRect(&tempRect);
-
- MoveTo(tempRect.left + 12,tempRect.top + 12);
- switch (Popup_I_Position) {
- case 1:
- DrawString("\pCentered");
- break;
- case 2:
- DrawString("\pTop Third");
- break;
- default:
- break;
- }
- } /* end of Redraw Menu */
- } /* end of Got Menu */
- } /* end of Check PopUpPosition */
- } /* of PopUp Flag */
- } while (ExitDialog == FALSE);
-
- if (itemHit == I_OK ) { /* OK to get results */
- /* Get results after dialog */
- GetDItem(GetSelection,I_B1Text, &DType, &DItem, &tempRect);
- GetIText(DItem, &(MInfo.Button1));
-
- GetDItem(GetSelection,I_B2Text, &DType, &DItem, &tempRect);
- GetIText(DItem, &(MInfo.Button2));
-
- GetDItem(GetSelection,I_B3Text, &DType, &DItem, &tempRect);
- GetIText(DItem, &(MInfo.Button3));
-
- GetDItem(GetSelection,I_CQText, &DType, &DItem, &tempRect);
- GetIText(DItem, &(MInfo.CharEquiv));
- MInfo.defaultItem = Popup_I_Default;
- MInfo.Buttons = Popup_I_Buttons - 1;
- MInfo.dIcon = Popup_I_Icons - 2;
- MInfo.dPlace = Popup_I_Position + 1;
- }
-
- DisposDialog(GetSelection);
- } /* end of D_Preferences() */
-
-
-